package cn.edu.neusoft.zengweidong707.intent;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private TextView tvSend;
    private Button btnSend;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tvSend = (TextView)findViewById(R.id.tvSend);
        btnSend = (Button)findViewById(R.id.btnSend);
        btnSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String message = tvSend.getText().toString();
                Intent intent = new Intent(MainActivity.this, Intent_Test.class);
                intent.putExtra("message", message);
                startActivityForResult(intent, 1);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
            case 1 :
                if(resultCode == RESULT_OK) {
                    String string = data.getStringExtra("return");
                    Toast.makeText(MainActivity.this, string, Toast.LENGTH_SHORT).show();
                }

        }
    }
}
